';
$('.item_container').append(str);
//$(this).parent().find('.item_container').append(str);
$('.autocomplete').focus();
}
}
$('body').on('keypress', '.item_quantity, .item_discount, .bill_discount_rate, .item_description, .cash_received, .phone_autocomplete', function(event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
$('body').on("keyup", ".item_quantity, .item_discount, .item_price" , function() {
var target=$(this);
updateRowTotal(target);
});
$('body').on("keyup", " .bill_discount_rate" , function() {
applyCommonDiscount();
});
$('body').on("click", ".btn_delete" , function() {
$(this).parent().parent().remove();
updateGrandTotal();
});
function applyCommonDiscount(){
var sub_total=$('.sub_total').val();
var bill_discount_rate=$('.bill_discount_rate').val();
var grand_total=sub_total;
var bill_discount_amount=0;
if(bill_discount_rate>0){
bill_discount_amount=parseFloat(sub_total)*parseFloat(bill_discount_rate)/100;
grand_total=sub_total-bill_discount_amount;
}
$('.grand_total').val(parseFloat(grand_total).toFixed(2));
$('.bill_discount_total').val(bill_discount_amount.toFixed(2));
}
function updateRowTotal(target){
var item_discount=0;
var sub_total=0;
var item_total=0;
var mrp=target.parent().parent().find('.item_price').val();
var quantity=target.parent().parent().find('.item_quantity').val();
var discount=target.parent().parent().find('.item_discount').val();
if(quantity>0 && mrp>0){
var sub_total=parseFloat(mrp)*parseFloat(quantity);
}
if(discount>0){
var item_discount=sub_total*parseFloat(discount)/100;
}
item_total=sub_total-item_discount;
//target.parent().parent().find('.item_price').val(sub_total.toFixed(2));
target.parent().parent().find('.item_total').val(item_total.toFixed(2));
updateGrandTotal();
}
function updateGrandTotal(){
var grand_total=0;
var bill_discount_rate=$('.bill_discount_rate').val();
$('.item_total').each(function(index, obj){
if(obj.value>0){
grand_total=grand_total+parseFloat(obj.value);
}
});
if(grand_total>0){
}
else{
grand_total=0;
}
$('.sub_total').val(grand_total.toFixed(2));
//applyCommonDiscount();
}
$('body').on('keypress', '.item_quantity', function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
createNewRow();
}
});
$('body').on('blur', '.item_quantity', function(event) {
// createNewRow();
});
$('body').on('click', '.btn_cancel', function(event) {
var url = $(this).attr('data-url');
window.location.href =url;
});
$( ".alphabets-only" ).keypress(function(e) {
var regex = new RegExp("^[a-zA-Z ]+$");
var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
if (regex.test(str)) {
return true;
}
else
{
return false;
}
});
$( ".email" ).blur(function(e) {
email=$(this).val();
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(emailReg.test( email )){
return true;
}
else{
$(this).val('');
}
});
function validateEmail(email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( email );
}
function validateName(name) {
var nameReg = /^[a-zA-Z ]+$/;
return nameReg.test( name );
}
function validatePhone(a) {
var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
if (filter.test(a)) {
return true;
}
else {
return false;
}
}
controller for autosuggest
public function parts_search(Request $request){
$input=$request->all();
$parts=Parts::select('id as sku_id','number as label','price','description' )
->where('status','1')
->where('number','LIKE',"%{$input['search']}%")
->get();
return response()->json(
$parts
, 200);
}